/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package gui2;

import entity.Customer;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Windows7
 */
public class GUIFeedBackCustomer extends javax.swing.JInternalFrame {
 Customer customer;
 
    /**
     * Creates new form GUIFeedBackCustomer
     */
    public GUIFeedBackCustomer( Customer customer) {
        try {
            initComponents();
            this.customer = customer;
            this.setResizable(false);
//            this.setTitle("Feedback of Customer");
            management.MyConnection.getConnection();
             management.GUIInteraction.readToTable("select Fb_Id,Fb_Cus, Fb_Admin,Fb_Status from Feedback where Customer_Id = '"+customer.getId()+"' ", tblFbCustomer);
           // management.GUIInteraction.readToTable(management.ManagerFeedBack.sqlTbl_FeedBack, tblFbCustomer);
        } catch (SQLException ex) {
            Logger.getLogger(GUIFeedBackCustomer.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public boolean checkValues() {

        if (!management.CheckForm.isEmpty(txaFbCus.getText())) {
            lblError.setText("Terms FeedBack : don't null");
            txaFbCus.requestFocus();
            return false;
        }
        return true;
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel1 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        tblFbCustomer = new javax.swing.JTable();
        jPanel1 = new javax.swing.JPanel();
        lblFeedCus = new javax.swing.JLabel();
        btnSend = new javax.swing.JButton();
        scpTerms = new javax.swing.JScrollPane();
        txaFbCus = new javax.swing.JTextArea();
        lblError = new javax.swing.JLabel();
        scpTerms1 = new javax.swing.JScrollPane();
        txaFbAdmin = new javax.swing.JTextArea();
        lblFeedCus1 = new javax.swing.JLabel();

        setPreferredSize(new java.awt.Dimension(1024, 650));

        jLabel1.setFont(new java.awt.Font("Times New Roman", 1, 36)); // NOI18N
        jLabel1.setForeground(new java.awt.Color(102, 0, 102));
        jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/feedback.png"))); // NOI18N
        jLabel1.setText("FEEDBACK  CUSTOMER");
        jLabel1.setPreferredSize(new java.awt.Dimension(206, 25));

        tblFbCustomer.setFont(new java.awt.Font("Tahoma", 0, 12)); // NOI18N
        tblFbCustomer.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "Title 1", "Title 2", "Title 3", "Title 4"
            }
        ));
        tblFbCustomer.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tblFbCustomerMouseClicked(evt);
            }
        });
        jScrollPane2.setViewportView(tblFbCustomer);

        jPanel1.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        lblFeedCus.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        lblFeedCus.setText("FeedBack :");
        lblFeedCus.setPreferredSize(new java.awt.Dimension(100, 25));

        btnSend.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        btnSend.setIcon(new javax.swing.ImageIcon(getClass().getResource("/icon/reply_24.png"))); // NOI18N
        btnSend.setText("Send");
        btnSend.setPreferredSize(new java.awt.Dimension(70, 30));
        btnSend.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSendActionPerformed(evt);
            }
        });

        txaFbCus.setColumns(20);
        txaFbCus.setRows(5);
        txaFbCus.setPreferredSize(new java.awt.Dimension(170, 100));
        scpTerms.setViewportView(txaFbCus);

        lblError.setFont(new java.awt.Font("Tahoma", 2, 10)); // NOI18N
        lblError.setForeground(new java.awt.Color(204, 0, 0));
        lblError.setText("*");
        lblError.setPreferredSize(new java.awt.Dimension(50, 25));

        txaFbAdmin.setColumns(20);
        txaFbAdmin.setRows(5);
        txaFbAdmin.setPreferredSize(new java.awt.Dimension(170, 100));
        scpTerms1.setViewportView(txaFbAdmin);

        lblFeedCus1.setFont(new java.awt.Font("Times New Roman", 1, 16)); // NOI18N
        lblFeedCus1.setText("Respond :");
        lblFeedCus1.setPreferredSize(new java.awt.Dimension(100, 25));

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(27, 27, 27)
                .addComponent(lblFeedCus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(lblError, javax.swing.GroupLayout.PREFERRED_SIZE, 159, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap())
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(scpTerms, javax.swing.GroupLayout.PREFERRED_SIZE, 300, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 88, Short.MAX_VALUE)
                        .addComponent(lblFeedCus1, javax.swing.GroupLayout.PREFERRED_SIZE, 76, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(scpTerms1, javax.swing.GroupLayout.PREFERRED_SIZE, 294, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(75, 75, 75))))
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGap(235, 235, 235)
                .addComponent(btnSend, javax.swing.GroupLayout.PREFERRED_SIZE, 103, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(0, 0, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(60, 60, 60)
                                .addComponent(lblFeedCus, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                            .addGroup(jPanel1Layout.createSequentialGroup()
                                .addContainerGap()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addComponent(scpTerms1, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addGroup(jPanel1Layout.createSequentialGroup()
                                        .addComponent(scpTerms, javax.swing.GroupLayout.PREFERRED_SIZE, 123, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                        .addComponent(lblError, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSend, javax.swing.GroupLayout.PREFERRED_SIZE, 47, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(61, 61, 61)
                        .addComponent(lblFeedCus1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(jScrollPane2)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(231, 231, 231)
                        .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 516, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 58, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 52, Short.MAX_VALUE)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 207, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(53, 53, 53))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void btnSendActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSendActionPerformed
        // TODO add your handling code here:
        try {
            if (checkValues()) {               
                String CusFb = txaFbCus.getText();           
                if (management.ManagerFeedBack.addFeedBack(customer.getId(),CusFb)) {                 
                   management.GUIInteraction.readToTable("select Fb_Id,Fb_Cus, Fb_Admin,Fb_Status from Feedback where Customer_Id = '"+customer.getId()+"' ", tblFbCustomer);
                    JOptionPane.showMessageDialog(this, "Successfull");
                } else {
                    JOptionPane.showMessageDialog(this, "UnSuccessfull");
                }
                txaFbCus.setText("");
            }
        } catch (Exception ex) {
            System.out.println(ex);
            ex.printStackTrace();
        }
    }//GEN-LAST:event_btnSendActionPerformed

    private void tblFbCustomerMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblFbCustomerMouseClicked
        int i = tblFbCustomer.getSelectedRow();
        txaFbAdmin.setText(String.valueOf(tblFbCustomer.getValueAt(i, 2)));
    }//GEN-LAST:event_tblFbCustomerMouseClicked

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnSend;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JLabel lblError;
    private javax.swing.JLabel lblFeedCus;
    private javax.swing.JLabel lblFeedCus1;
    private javax.swing.JScrollPane scpTerms;
    private javax.swing.JScrollPane scpTerms1;
    private javax.swing.JTable tblFbCustomer;
    private javax.swing.JTextArea txaFbAdmin;
    private javax.swing.JTextArea txaFbCus;
    // End of variables declaration//GEN-END:variables
}
